//
//  ZYCCourseDetailHeaderView.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/23.
//

#import "ZYCCourseDetailHeaderView.h"
#import <UIImageView+WebCache.h>
#import "ZYCCourseRegistrationDetailModel.h"
@interface ZYCCourseDetailHeaderView ()

@property (nonatomic, strong) UIImageView *courseImageView;
@property (nonatomic, strong) UILabel *courseTitleLabael;
@property (nonatomic, strong) UILabel *courseStatusLabel;
@property (nonatomic, strong) UILabel *line;

@end
@implementation ZYCCourseDetailHeaderView

- (void)setModel:(ZYCCourseRegistrationDetailModel *)model{
    _model = model;
    NSURL *url  = [NSURL URLWithString:[NSString stringWithFormat:@"%@/zd-system-service%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"sdfz_url"],model.courseImg]];
    [_courseImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"bjc"]];
    _courseTitleLabael.text = [NSString stringWithFormat:@"开课班级:%@",model.className];
    
    //报名状态（1-未开始，2-进行中，3-已结束）
    NSInteger enrollStatus = [model.enrollStatus integerValue];
    if (enrollStatus == 1) {
        _courseStatusLabel.backgroundColor = HEX_RGB(@"#EB9F28");
    }else if (enrollStatus == 2) {
        _courseStatusLabel.backgroundColor = HEX_RGB(@"#39A85B");
    }else if (enrollStatus == 3) {
        _courseStatusLabel.backgroundColor = HEX_RGB(@"#B9B9B9");
    }
    _courseStatusLabel.text = model.enrollStatusStr;
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = HEX_RGB(kBgWhiteColor);
        [self addSubview:self.courseImageView];
        [self addSubview:self.courseTitleLabael];
        [self addSubview:self.courseStatusLabel];
        [self addSubview:self.line];
        
        [self.courseImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(13.5f);
            make.right.equalTo(self).offset(-13.5f);
            make.top.equalTo(self).offset(15.0f);
            make.height.mas_equalTo(183.0f);
        }];
        
        [self.courseTitleLabael mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(13.5f);
            make.top.equalTo(self.courseImageView.mas_bottom).offset(16.0f);
        }];
        
        [self.courseStatusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-13.5f);
            make.centerY.equalTo(self.courseTitleLabael);
            make.size.mas_equalTo(CGSizeMake(56.0f, 23.0f));
        }];
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            make.height.mas_equalTo(5.0f);
        }];
        
    }
    return self;
}

- (UIImageView *)courseImageView {
    if (!_courseImageView) {
        _courseImageView = [[UIImageView alloc] init];
        _courseImageView.backgroundColor = HEX_RGB(@"#D8D8D8");
    }
    return _courseImageView;
}

- (UILabel *)courseTitleLabael {
    if (!_courseTitleLabael) {
        _courseTitleLabael = [UILabel LabelWithFont:kSystemBoldFont(17.0f) titleColor:HEX_RGB(@"#262A28") textAlignment:ZZTextAlignmentLeft];
    }
    return _courseTitleLabael;
}

- (UILabel *)courseStatusLabel {
    if (!_courseStatusLabel) {
        _courseStatusLabel = [[UILabel alloc] init];
        _courseStatusLabel.textColor = HEX_RGB(kTitleWhiteColor);
        _courseStatusLabel.font = kCustomFont(@"PingFangSC-Light", 12.0f);
        _courseStatusLabel.layer.cornerRadius = 11;
        _courseStatusLabel.layer.masksToBounds = YES;
        _courseStatusLabel.backgroundColor = HEX_RGB(@"#EB9F28");
        _courseStatusLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _courseStatusLabel;
}
- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = HEX_RGB(@"#F9F9F9");
    }
    return _line;
}
@end
